package 排序;

/**
 * @Author: biubiu0002
 * @Date: 2021-07-08 15:25
 **/
public class 快速排序 {

    public static void main(String[] args) {
        int[] nums = {3,5,2,4,1,8,6,7};
        new 快速排序().qsort(nums,0, nums.length-1);
        for (int i : nums) {
            System.out.println(i);
        }

    }

    int partition(int[] arr, int low, int high){
        int pivot = arr[low];
        while(low<high){
            while (low<high&&arr[high]>=pivot){
                high--;
            }
            arr[low]=arr[high];
            while(low<high&arr[low]<=pivot){
                low++;
            }
            arr[high]=arr[low];
        }
        arr[low] = pivot;
        return low;
    }

    void qsort(int[] array, int low, int high){
        if (low<high){
            int mid = partition(array, low, high);
            qsort(array,low,mid-1);
            qsort(array,mid+1,high);

        }


    }


}
